package com.java.factory.simplefactory;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import com.java.factory.pizza.Pizza;

public class OrderPizza {
    SimplePizzaFactory mSimplePizzaFactory;
    
    public OrderPizza(SimplePizzaFactory mSimplePizzaFactory){
    	setFactory(mSimplePizzaFactory);
    }
    
    public void setFactory(SimplePizzaFactory mSimplePizzaFactory){
    	Pizza pizza = null;
    	String ordertype;
    	
    	this.mSimplePizzaFactory = mSimplePizzaFactory;
    	
    	do{
    		ordertype = gettype();
    		pizza = mSimplePizzaFactory.CreatePizza(ordertype);
    		if(pizza != null){
    			pizza.prepare();
    			pizza.bake();
    			pizza.cut();
    			pizza.box();
    		}
    	}while(true);
    }
    
    private String gettype(){
    	try {
			BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
			System.out.println("input pizza type:");
			String str = strin.readLine();
			
			return str;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return "";
		}
    	
    }
}
